mod lib_message_queue;
mod lib_namespace;

use lib_message_queue::*;
use libc::sleep;
use std::thread::{current, spawn};
fn message_queue_test() {
    let queue = create_or_get_queue(c"/".as_ptr(), 2025);
    let join_handle2 = spawn(move || loop {
        if let Ok(msg) = queue_recv_msg(queue, 20) {
            println!("{:?} recv {:?}", current().id(), msg);
        }
        unsafe {
            sleep(1);
        }
    });
    let join_handle1 = spawn(move || {
        let mut count = 0;
        loop {
            if let Ok(_) = queue_send_msg(queue, 20, format!("hello ji hai {} xuan", count).into_bytes()) {
                println!("{:?} send msg {count}", current().id())
            }
            unsafe {
                sleep(1);
                count += 1;
            }
        }
    });

    join_handle1.join().unwrap();
    join_handle2.join().unwrap();
}
